#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "builtins.h"

int is_builtin(Command *commands) {
    return strcmp(commands->args, "cd") == 0 ||
           strcmp(commands->args, "exit") == 0;
}

int execute_builtin(Command *commands) {
    if (strcmp(commands->args, "cd") == 0) {
        return shell_cd(commands);
    }
    if (strcmp(commands->args, "exit") == 0) {
        return shell_exit(commands);
    }
    return 0;
}

int shell_cd(Command *cmd) {
    if (cmd->args == NULL) {
        fprintf(stderr, "cd: missing argument\n");
        return 1;
    }
    if (chdir(cmd->args) != 0) {
        perror("cd");
    }
    return 1;
}

int shell_exit(Command *cmd) {
    exit(0);
    return 1;
}
